AddCSLuaFile("shared.lua");

SWEP.PrintName			= "Red energy";
SWEP.Author			= "Brian Nevec";
SWEP.Slot				= 2;
SWEP.SlotPos			= 3;
SWEP.Purpose			= "Jacked from a drop ship";
SWEP.Instructions		= "Left Click: Fire";

SWEP.Category			= "SMOD";

SWEP.Spawnable			= true;
SWEP.AdminSpawnable		= false;

SWEP.ViewModel			= "models/weapons/v_smg1.mdl";
SWEP.WorldModel		= "models/weapons/w_smg1.mdl";

SWEP.Weight			= 25;
SWEP.AutoSwitchTo		= false;
SWEP.AutoSwitchFrom		= false;

SWEP.Primary =
{
	
	ClipSize			= -1,
	DefaultClip		= -1,
	Automatic			= true,
	Ammo				= "none"
	
}

//secondary settings
SWEP.Secondary =
{
	
	ClipSize			= -1,
	DefaultClip		= -1,
	Automatic			= true,
	Ammo				= "none"
	
};

function SWEP:Initialize( )
	
	if( SERVER ) then
		
		//set the hold type
		self:SetWeaponHoldType( "smg" );
		
	end
	
end

//when we want to attack with the primary
function SWEP:PrimaryAttack( )
	
end

//when we think
function SWEP:Think( )
	
end

//when we deploy
function SWEP:Deploy( )
	
	self.Weapon:SendWeaponAnim( ACT_VM_DRAW );
	
	return true;
	
end

if( !CLIENT ) then return; end

SWEP.BeamMaterial = Material( "cable/redlaser" );
SWEP.RefractMat = Material( "egon_ringbeam" );

function SWEP:ViewModelDrawn( )
	
	local vm = self.Owner:GetViewModel( );
	local id = vm:LookupAttachment( "muzzle" );
	local at = vm:GetAttachment( id );
	
	local origin = at.Pos;
	local endpos = self.Owner:GetEyeTrace( ).HitPos;
	
	local length = 16;
	local segments = math.floor( origin:Distance( endpos ) / length );
	local spread = 1;
	local width, fraction = 32;
	
	render.SetMaterial( self.BeamMaterial );
	
	render.StartBeam( segments + 1 );
		
		for i = 0, segments do
			
			fraction = 1 - i / segments;
			
			local target_pos = origin + ( ( endpos - origin ) * ( i / segments ) );
			target_pos = target_pos + VectorRand( ):GetNormal( ) * math.random( spread );
			
			render.AddBeam( target_pos, width * fraction, 0, color_white );
			
		end
		
		render.AddBeam( endpos, width * fraction, 0, color_white );
		
	render.EndBeam( );
	
	render.UpdateRefractTexture( );
	
	render.SetMaterial( self.RefractMat );
	render.DrawBeam( origin, endpos, width * 1.25, 0, 0, color_white );
	
end